<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>JS</title>
</head>
<body>
    <span><input type="text" id="number"></span>
    <button onclick="JieCheng()">阶乘</button>
    <span id="span">结果</span><br>

    <span><input type="text" id="num"></span>
    <button onclick="DaXiao()">猜</button>
    <span id="res">结果</span><br>

    <script>
        function JieCheng() {
            var num = document.getElementById("number").value;
            var result = 1;
            var i;
            for(i = 0; i <= num; i++) {
                if(0 === i){
                    result = 1;
                } else {
                    result = result * i;
                }
            }
            var span = document.getElementById("span");
            span.innerHTML = result;
        }

        function DaXiao() {
            var num = document.getElementById("num").value;
            var number = parseInt(Math.random() * 100 + 1);
            var result;
            if(num > number) {
                result = '大了，数字是：' + number;
            } else if(num < number) {
                result = '小了，数字是：' + number;
            } else {
                result = '猜对了';
            }
            var res = document.getElementById("res");
            res.innerText = result;
        }
    </script>
</body>
</html>